package com.edu.service.impl;

import com.edu.bean.User;
import com.edu.mapper.UserMapper;
import com.edu.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.awt.print.Book;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:zyn
 * @Date:2025/11/14--11:47:33
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;
    @Override
    public int addUser(List<User> userList) {
        return userMapper.insertUser(userList);
    }

    @Override
    public int deleteUser(int userId) {
        return userMapper.deleteUser(userId);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public User selectUserById(int userId) {
        return userMapper.selectUserById(userId);
    }

    @Override
    public Map<String, Object> login(String username, String password) {
        User user= userMapper.selectUserByNameAndPassword(username, password);
        Map<String,Object> loginUser=new HashMap<>();
        if(user != null){
            loginUser.put("msg","登录成功");
        }else{
            user=userMapper.selectUserByName(username);
            if(user == null){
                loginUser.put("msg","账号不存在");
            }else {
                loginUser.put("msg","密码错误");
            }
        }
        return loginUser;
    }
}
